package simple.cashflow.service.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import simple.cashflow.model.Jabatan;
import simple.cashflow.service.JabatanService;

@Service("jabatanService")
public class JabatanServiceImpl implements JabatanService {
	
	@Autowired
	private SessionFactory sessionFactory;
	private String hqlCariDariKode = "from Jabatan j where j.kodeJab =:kode";
	private String hqlCariSemua = "from Jabatan";

	@Override
	public void simpanJabatan(Jabatan jabatan) {
		sessionFactory.getCurrentSession().saveOrUpdate(jabatan);
	}

	@Override
	public void hapusJabatan(Jabatan jabatan) {
		sessionFactory.getCurrentSession().delete(jabatan);
	}

	@Override
	public Jabatan cariJabatanDariKode(String kodeJab) {
		return (Jabatan) sessionFactory.getCurrentSession().createQuery(hqlCariDariKode)
					.setParameter("kode", kodeJab).uniqueResult();
	}

	@Override
	public List<Jabatan> cariSemuaJabatan() {
		return sessionFactory.getCurrentSession().createQuery(hqlCariSemua).list();
	}

}
